
import 'package:dio/dio.dart';
import 'package:ycbl/model/bl_error_entity.dart';
import 'package:ycbl/model/HomeModels/home_model.dart';
import 'package:ycbl/net/http/bl_request_manager.dart';
import 'package:ycbl/utils/log_util.dart';
import 'package:ycbl/widget/provider/base_view_state_list_model.dart';

class HomeViewModel extends BaseViewStateListModel<HomeData> {
  var url;
  HomeViewModel(String urlGet){
    this.url = urlGet;
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
  }
  @override
  internalLoadData({int startIndex, Function(List<HomeData> p1) onListSuccess, Function(BLErrorEntity p1) onListError}) {
    Map<String, dynamic> headersMap = new Map<String, dynamic>();
    headersMap["jsonFormat"]="1";
    //按照分层 网络请求应该写在 repository 中，这里测试就不放了
    BLRequestManager.getInstance().get(url, options:Options(headers:headersMap),onSuccess: (data){
      LogUtil.e("网络请求成功后的结果");
      LogUtil.e(data);
      var model = HomeModel.fromJson(data);
      if(model?.data != null) {

        onListSuccess(model.data);
      }else {
        onListError(BLErrorEntity(message: '加载数据失败'));
      }
    }, onError: onListError);

  }

  @override
  onLoadComplete(List<HomeData> newListData) {
    LogUtil.d('onLoadComplete');
    return super.onLoadComplete(newListData);
  }


}